/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cloudminga.database;

/**
 *
 * @author jyoti
 */
import com.globussoft.util.FormatedFileSize;
import com.globussoft.util.FormatedTime;
import java.sql.*;

public class Databse_HistoryOnDate {

    Statement statement;
    Connection connection = null;
    ResultSet resultSet = null;
    ResultSet resultSet1;
    CallableStatement callableStatement;
    ResultSetMetaData resultsetMetaData;
    String query;
    String email_Id;
    TableModel table_Model;
    int colCount = 0;
    int rowCount;
    String date;

    public Databse_HistoryOnDate() {
        try {
            // Establising database connection
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:jtds:sqlserver://mssql502.ixwebhosting.com/C230527_masterdatabase", "C230527_sumit", "Globus1234");
                    } // End of try
        catch (Exception exception) {
            System.out.println("Error in connection " + exception);
        }// End of catch
    }

    public Object[][] get_HistoryOnDate(String email, String date1) {
        this.date = date1;
        int temp;
        int row = 0;
        this.email_Id = email;
        Object[][] obj= null;
        try {
            callableStatement = connection.prepareCall("{call sp_Pomblast_GetBackupDetailsByDate(?,?)}", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            callableStatement.setString(1, email_Id);
            callableStatement.setString(2, date);
            resultSet = callableStatement.executeQuery();
            // rsmt is ResultSetMetaData to find out the total columns of the table
            resultsetMetaData = resultSet.getMetaData();
            colCount = resultsetMetaData.getColumnCount();
            resultSet.last();
            rowCount = resultSet.getRow();
            resultSet.beforeFirst();
            System.out.println("number of rows are :  " + rowCount);
            obj= new Object[rowCount][colCount];
           //table_Model = new TableModel(rowCount, colCount + 2);
            resultSet.beforeFirst();
            while (resultSet.next()) {
                for(int j=0;j<colCount;j++)
                {
                    obj[row][j]=resultSet.getObject(j+1);
                }
                row++;
              }
//            while (resultSet.next()) {
//                table_Model.setValueAt(row, 0, resultSet.getString(1));
//                String file =resultSet.getString(2);
//                String fileName =file.substring(file.replace("\\","/").lastIndexOf("/")+1);
//                String dirName  =file.substring(0,file.replace("\\","/").lastIndexOf("/"));
//                table_Model.setValueAt(row, 1, fileName);
//                table_Model.setValueAt(row, 2, dirName);
//                long size=resultSet.getLong(3);
//                long time=resultSet.getLong(4);
//                float transferRate =(float)size*1000/(time*1024);
//                table_Model.setValueAt(row, 3, FormatedFileSize.getFormatedFileSize(size));
//                table_Model.setValueAt(row, 4, FormatedTime.getFormatedTimeString(time));
//                table_Model.setValueAt(row, 5, transferRate);
//                table_Model.setValueAt(row++, 6, resultSet.getString(5));
//            }
        } catch (Exception exception) {
            exception.printStackTrace();

        }
        return obj;
    }
}
